package com.ruoyi.quartz.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.quartz.domain.StockBear;
import com.ruoyi.quartz.service.IStockBearService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 变化趋势Controller
 * 
 * @author ruoyi
 * @date 2023-12-19
 */
@Controller
@RequestMapping("/finance/bear")
public class StockBearController extends BaseController
{
    private String prefix = "finance/bear";

    @Autowired
    private IStockBearService stockBearService;

    @RequiresPermissions("finance:bear:view")
    @GetMapping()
    public String bear()
    {
        return prefix + "/bear";
    }

    /**
     * 查询变化趋势列表
     */
    @RequiresPermissions("finance:bear:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(StockBear stockBear)
    {
        startPage();
        List<StockBear> list = stockBearService.selectStockBearList(stockBear);
        return getDataTable(list);
    }

    /**
     * 导出变化趋势列表
     */
    @RequiresPermissions("finance:bear:export")
    @Log(title = "变化趋势", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(StockBear stockBear)
    {
        List<StockBear> list = stockBearService.selectStockBearList(stockBear);
        ExcelUtil<StockBear> util = new ExcelUtil<StockBear>(StockBear.class);
        return util.exportExcel(list, "变化趋势数据");
    }

    /**
     * 新增变化趋势
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存变化趋势
     */
    @RequiresPermissions("finance:bear:add")
    @Log(title = "变化趋势", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(StockBear stockBear)
    {
        return toAjax(stockBearService.insertStockBear(stockBear));
    }

    /**
     * 修改变化趋势
     */
    @RequiresPermissions("finance:bear:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        StockBear stockBear = stockBearService.selectStockBearById(id);
        mmap.put("stockBear", stockBear);
        return prefix + "/edit";
    }

    /**
     * 修改保存变化趋势
     */
    @RequiresPermissions("finance:bear:edit")
    @Log(title = "变化趋势", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(StockBear stockBear)
    {
        return toAjax(stockBearService.updateStockBear(stockBear));
    }

    /**
     * 删除变化趋势
     */
    @RequiresPermissions("finance:bear:remove")
    @Log(title = "变化趋势", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(stockBearService.deleteStockBearByIds(ids));
    }
}
